//
// Created by xili on 2024/9/2 20:46.
// GO BIG OR GO HOME.
//
#include "leetcode.h"

class Solution {
public:
    int minimumAddedInteger(vector<int> &nums1, vector<int> &nums2) {
        ranges::sort(nums1);
        ranges::sort(nums2);
        for (int i = 2; i > 0; i--) {
            int x = nums2[0] - nums1[i];
            int j = 0;
            for (int k = i; k < nums1.size(); k++) {
                if (nums2[j] == nums1[k] + x && ++j == nums2.size()) {
                    return x;
                }
            }
        }
        return nums2[0] - nums1[0];
    }
};